package com.starbaba.externalSMSConfig.view;

import com.base.common.log.LogService;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ModelDriven;
import com.starbaba.core.utils.PropertyParamMapBuilder;
import com.starbaba.core.utils.Struts2Utils;
import com.starbaba.core.utils.json.JsonUtils;
import com.starbaba.core.web.struts2.BaseAction;
import com.starbaba.externalSMSConfig.model.SmsConfigResult;
import com.starbaba.externalSMSConfig.service.ExternalSMSService;
import com.starbaba.externalSMSConfig.service.impl.ExternalSMSServiceImpl;
import com.tuanzi.server.loan_base.model.db.activity.RegisterRecommendActivity;

@SuppressWarnings("serial")
public class ExternalSMSAction extends BaseAction implements ModelDriven<RegisterRecommendActivity>{
	
	private RegisterRecommendActivity bean;
	
	ExternalSMSService service=new ExternalSMSServiceImpl();
	
	public String showPage(){
		
		paramsMap=PropertyParamMapBuilder.buildFromHttpRequest(Struts2Utils.getRequest(), paramsMap);
		
		service.showpage(paramsMap);
		
		return Action.SUCCESS;
	}
	
	
	public void saveOrUpdate(){
		String activity_type = bean.getActivity_type();
		int message_type = bean.getMessage_type();
		
		try {
			SmsConfigResult result = service.saveOrUpdateInfo(activity_type, message_type);
			
			sendJsonMessage(JsonUtils.toJson(result, null, true, null, false));
			
		} catch (Exception e) {
			LogService.error("保存配置外部推广回拉短信出错",e);
			e.printStackTrace();
		}
	}
	
	
	

	@Override
	public RegisterRecommendActivity getModel() {
		if(null==bean){
			bean=new RegisterRecommendActivity();
		}
		return bean;
	}
}
